package org.alexsotob.roo.addon.flyway;

import org.springframework.roo.support.util.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

class EclipseLinkPersistenceFileModifier implements PersistenceFileModifier {

	private static final String DDL_GENERATION_PROPERTY_NAME = "eclipselink.ddl-generation";

	@Override
	public void avoidDatabaseAutoCreation(Document persistenceDocument) {

		Element synchronizeMappingsProperty = XmlUtils.findFirstElement(
				"/persistence/persistence-unit/properties/property[@name= '"
						+ DDL_GENERATION_PROPERTY_NAME + "']",
				persistenceDocument.getDocumentElement());

		if (synchronizeMappingsProperty != null) {
			synchronizeMappingsProperty.setAttribute("value", "none");
		}

	}
}
